home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / DOSTIPS4.ZIP / DOSBATCH.TXT < prev    next >
Text File  |  1986-06-28  |  29KB  |  581 lines

  1.                            Batch Logs
  2.      (PC Magazine Vol 5 No 1 January 14, 1985 User-to-User)
  3.  
  4.      In developing a large software project you're likely to end up
  5. writing a complex batch file to handle all the compiles, assemblies
  6. and links required.  Sitting around for hours monitoring the batch
  7. file to make sure everything works properly isn't fun.  It would be
  8. handy if all the output from a batch file could be redirected to a
  9. file to be inspected later.  Unfortunately, you can't do it simply
  10. by redirecting the output of the master batch file: build.bat>logfile.
  11.      However, there is an obscure way to do the same thing.  First,
  12. make the very last line of your batch file the DOS command EXIT.  But
  13. before running this batch file, load another copy of COMMAND.COM and
  14. redirect its output to the log file:  command>logfile.
  15.      With this trick, all screen output is redirected to your log file.
  16. However, since the DOS prompt disappears and your typing will no longer
  17. echo on the screen, be sure to type the name of your batch file
  18. carefully, since you can't see it.  All the output of the batch file
  19. will now to into your log file and the EXIT command at the bottom of
  20. the batch file will return everything to normal.
  21.      Editor's Note: This technique demonstrates yet another benefit of
  22. loading COMMAND.COM as a secondary command processor.  An even more
  23. interesting one is during a session with a windowing program that
  24. doesn't normally give you access to DOS commands.  It's fairly simple
  25. to record a batch session without loading in a second COMMAND.COM;
  26. just toggle your printer echo on with Ctrl-PrtSc or Ctrl-P and
  27. everything that appears on the screen will also be printed.  When
  28. you're done, toggle it off the same way.
  29.  
  30. -----------------------------------------------------------------
  31.                           Better Pauser
  32.      (PC Magazine Vol 5 No 1 January 14, 1986 User-to-User)
  33.  
  34.      The DOS PAUSE command in a batch file will have the computer stop
  35. and wait for a key.  STOP.COM replaces the PAUSE command and gets rid
  36. of the "Strike a key when ready . . ." message.  You can instruct
  37. STOP.COM to proceed when any key is pressed, or wait for a specific
  38. key (extended codes are allowed).  Create STOP.COM with STOP.BAS
  39. below.  STOP.COM will be either 11 or 19 bytes long depending on your
  40. choice of trigger keys.
  41.  
  42. 100 'STOP.BAS
  43. 110 DIM D(19):FOR Y=1 TO 11:READ D(Y):NEXT:DEF SEG=&H40
  44. 120 PRINT "Type specific key OR '?' for any key ";
  45. 130 LY$=INKEY$:IF LY$="" GOTO 130
  46. 140 TL=PEEK(26):TL=TL-2:IF TL<30 THEN TL=60
  47. 150 C1=PEEK(TL):C2=PEEK(TL+1)
  48. 160 IF C1<>0 THEN 190
  49. 170 SI=19:FOR Y=10 TO 19:READ D(Y):NEXT
  50. 180 D(15)=C2:D(6)=60:D(7)=0:GOTO 200
  51. 190 SI=11:IF C1<>63 THEN D(6)=60:D(7)=C1
  52. 200 OPEN "STOP.COM" AS #1 LEN=1
  53. 210 FIELD 1,1 AS PH$
  54. 220 FOR Y=1 TO SI:LSET PH$=CHR$(D(Y)):PUT #1:NEXT
  55. 230 PRINT:PRINT "STOP.COM created.":CLOSE #1:END
  56. 240 DATA 184,8,12,205,33,56,192,117,247,205
  57. 250 DATA 32,180,8,205,33,60,0,117,239,205,32
  58.  
  59.      The following is an assembler code version that will proceed only
  60. when the F1 key is pressed.
  61.  
  62. xxxx:0100  B8080C   MOV   AX,0C08
  63. xxxx:0103  CD21     INT   21
  64. xxxx:0105  3C00     CMP   AL,00
  65. xxxx:0107  75F7     JNZ   0100
  66. xxxx:0109  B408     MOV   AH,08
  67. xxxx:010B  CD21     INT   21
  68. xxxx:010D  3C3B     CMP   AL,3B
  69. xxxx:010F  75EF     JNZ   0100
  70. xxxx:0111  CD20     INT   20
  71.  
  72.      Use DOS 2.0 or later DEBUG by first typing in DEBUG STOP.COM,
  73. then typing A, then the rightmost two columns above.  Finish it off
  74. by hitting the Enter key twic, then typing RCX, then 13, then W, then
  75. Q, hitting the Enter key after each.  The 3B in the CMP AL,3B line is
  76. the extended scan code for F1; to use F2 as the trigger, replace the
  77. 3B with 3C, etc.
  78.      Editor's Note:  By creating STOP.COM and inserting the word STOP
  79. in a batch file, you do halt the operation of the batch file without
  80. the conventional PAUSE message.  However, you have to tell the user to
  81. hit a key, presumably with an ECHO subcommand, so you're really not
  82. gaining much, and you have to precede the STOP line with an ECHO OFF,
  83. or you'll see the word STOP on-screen.  In addition, the PAUSE works
  84. so well that if the "Strike . . ." message is really a bother, just
  85. change it.  Use DEBUG with a copy of COMMAND.COM.  At the DEBUG
  86. prompt, type RCX and hit the Enter key twice to see how long your
  87. version of COMMAND.COM is.  Then enter the following DEBUG search
  88. instruction:  S 100 XXXX "Strike a key" (replacing the XXXX with the
  89. length reported when you typed RCX).  The last four digits of the new
  90. number DEBUG reports are the address of the "Strike . . ." message --
  91. for DOS 3.1 the address would be 491E.  You can use the DEBUG E command
  92. to replace it with something the same length, such as "Hit any key to
  93. continue" or you can blank it out if you want by entering 23 spaces
  94. between a pair of quotation marks.  If the new message is shorter than
  95. the old, pad out the difference with spaces.
  96.  
  97.  
  98. -----------------------------------------------------------------
  99.  
  100.                      Interactive Batch Files
  101.               (PC World January 1986 Star-Dot-Star)
  102.  
  103.      DOS batch file commands don't support one very useful feature --
  104. user interaction.  The program QUERY.COM, when executed, displays a
  105. message and waits for a single-keystroke reply.  A batch file can then
  106. test ERRORLEVEL to determine the user's selection.
  107.      To use the program, type QUERY followed by the text you want
  108. displayed as a prompt, then an "at" sign (@) followed by the valid
  109. response characters.  QUERY will set the ERRORLEVEL value to correspond
  110. to the sequence of the characters listed.
  111.      For example, when the lines shown in USERTEST.BAT execute, the PC
  112. will display the message "Do you want to see a list of files?" and wait
  113. for you to press Y or N (upper- or lowercase); all other keystrokes are
  114. ignored.  If you press Y, ERRORLEVEL will be set to 1.  If you type N,
  115. ERRORLEVEL will be set to 2.  Note that because DOS performs an "equal
  116. to or greater than" test for ERRORLEVEL, you must test the highest
  117. values first.
  118.      If no @ character is found, QUERY will simply display the message.
  119. If a question mark is included at the end of the response list, QUERY
  120. will match any character.  Don't put a space at the end of the list
  121. unless you want the <Space> bar to be considered a valid response.
  122.  
  123. USERTEST.BAT:
  124. echo off
  125. cls
  126. query Do you want to see a list of files? @yn
  127. if errorlevel 2 goto no
  128. if errorlevel 1 goto yes
  129. :no            don't show list of files
  130. goto end
  131. :yes           do show list of files
  132. dir
  133. goto end
  134. :end
  135.  
  136. -----------------------------------------------------------------
  137.                        Batch Line Skipper
  138.        (PC Magazine Vol 5 No 3 Feb 11, 1986 User-to-User)
  139.  
  140.      The DOS 3.1 COMMAND.COM patch to skip a line in a batch file with
  141. the ECHO + space + space construction (User-to-User, Vol 4 No 24) is
  142. useful only when running a batch file on a system that has the patched
  143. COMMAND.COM.  Anyone else who distributes batch files needs a way to
  144. skip lines in batch files on all systems.  With ECHO OFF, the
  145. construction ECHO ^H (^H means hold down the Ctrl key and hit the H
  146. key) will skip a line using both DOS 2.1 and 3.1.  To demonstrate this,
  147. create a batch file called LINE.BAT with these lines:
  148.  
  149. ECHO OFF
  150. ECHO This is line 1.
  151. ECHO ^H
  152. ECHO This is line 3.
  153.  
  154. To insert the Ctrl-H you will need an editor or word processor that is
  155. able to embed control characters.  This can be done with WordStar by
  156. holding down the Ctrl key and typing PH.  Using EDLIN this can be done
  157. by holding down the Ctrl key and typing VH.
  158.      Editor's Note: The extended ASCII character set offers three
  159. blanks -- CHR$(0), CHR$(32) and CHR$(255). CHR$(32) is the conventional
  160. between-word space, while CHR$(0) is a null and CHR$(255) is a high-bit
  161. space.  Following ECHO with either a CHR$(0) or a CHR$(255) will skip a
  162. line.  Two other ways to create these line skippers are in BASIC and in
  163. DEBUG.  WordStar lets you make the ECHO + CHR$(255) (but not CHR$(0))
  164. by holding down the Alt key, typing 255 on the number pad (not the top
  165. row), and then releasing the Alt key -- if you do this, a ^ appears.
  166. If you use DEBUG, type in the whole file using your word processor (or
  167. even the DOS COPY CON: facility) but put a single dummy character where
  168. the CHR$(0) or CHR$(255) goes.  Then get into DEBUG and replace the
  169. dummy character with either a 0 for CHR$(0) or an FF for CHR$(255), or
  170. just follow ECHO with a period -- and no intervening space.
  171.  
  172.  
  173. -----------------------------------------------------------------
  174.                           REMless REMs
  175.        (PC Magazine Vol 5 No 3 Feb 11, 1986 User-to-User)
  176.  
  177.      Well-chosen remarks within a batch file can be very valuable in
  178. prompting a user to swap disks or to display a title or logo.  However,
  179. it would be nice to eliminate the actual word REM from the display.
  180. The trick is to place a string of backspaces (CHR$(8)) at the beginning
  181. of the remark line.  You can't do this when using the DOS COPY CON:
  182. batch creation method, since DOS uses the Backspace key for making
  183. corrections.  But any word processor that allows embedded control codes
  184. makes it easy.
  185.      In the following REMLESS.BAT example, the first remark will be
  186. preceded by a REM, while the second won't.  (Each backspace here
  187. appears as a lowercase h.)
  188.  
  189. CLS
  190. REM this is a remark
  191. REMhhhthis is a REMless remark
  192.  
  193. You can also use this technique along with SideKick's ability to enter
  194. and edit the upper 128 ASCII graphics symbols to create attractive
  195. titles.
  196.      Editor's Note:  This eliminates the problem of displaying REMs,
  197. but it's just as easy to start batch files with ECHO OFF and then ECHO
  198. comments.  If you have a word processor such as SideKick or WordStar
  199. that lets you embed control characters, you can create each backspace
  200. in REMLESS.BAT by typing Ctrl-PH (they'll show up as ^H's).  Otherwise,
  201. run the REMLESS.BAS program below.
  202.  
  203. 100 'REMLESS.BAS: Creates REMLESS.BAT test batchfile
  204. 110 OPEN "remless.bat" FOR OUTPUT AS #1
  205. 120 PRINT #1,"CLS"
  206. 130 PRINT #1,"REM this is a remark"
  207. 140 PRINT #1,"REM";STRING$(3,8);"this is a REMless remark"
  208. 150 CLOSE:END
  209.  
  210.  
  211. -----------------------------------------------------------------
  212.  
  213.              Improved Return to a Previous Directory
  214.              (PC World January 1986 The Help Screen)
  215.  
  216.      This technique provides a more elegant method to make a batch file
  217. that changes directories switch back to the directory from which the
  218. batch file was invoked.  It assumes that batch files are kept in a
  219. directory called BATCH and that a PATH command that includes the BATCH
  220. directory is executed by the hard disk's AUTOEXEC.BAT file.
  221.      This routine relies on a 3-character ASCII file called CDSPACE.TXT
  222. and three DOS commands that you can add to any batch file that changes
  223. directories.  First create CDSPACE.TXT and store it in the hard disk's
  224. BATCH directory with the following procedure.  At DOS, type COPY CON C:
  225. \BATCH\CDSPACE.TXT and press Enter.  Then type CD and press the space
  226. bar.  To write the file to disk, press F6 and Enter.
  227.      After creating SAMPLE.BAT below, type PATH and press Enter to
  228. verify that C:\BATCH is included in the list of directories that are
  229. to be searched for the commands or batch files not in the current
  230. directory.  (If it is not included, type PATH C:\BATCH and press
  231. Enter.)  Make the root directory current by typing CD\ and press
  232. Enter, and run the batch file by typing SAMPLE followed by Enter.
  233.      The first line of SAMPLE.BAT copies the 3-character ASCII file
  234. CDSPACE.TXT into a file called RESET_CD.BAT in the BATCH directory of
  235. drive C:.  The ">NUL" at the end of this line redirects the screen
  236. output of the copy command, "1 file(s) copied," to the NUL device
  237. (the equivalent of "nothing") so that the copy message is not displayed
  238. on the screen.  The double greater-than symbols in the second line
  239. cause the CD (current directory) command's output (in this case,
  240. C:\), which is normally displayed on screen, to be appended to the 3
  241. characters of RESET_CD.BAT.  RESET_CD.BAT now consists of the command
  242. CD followed by the name of the directory from which SAMPLE.BAT was
  243. invoked.  These two lines, of course, must be executed before the
  244. batch file changes directories.  SAMPLE.BAT then displays the current
  245. directory (the directory from which it was invoked), changes
  246. directories, and displays the name of the new current directory.  The
  247. last line of SAMPLE.BAT calls RESET_CD.BAT, the file that was created
  248. by SAMPLE.BAT's first two lines.  RESET_CD.BAT makes the directory
  249. from which SAMPLE.BAT was called the current directory.
  250.  
  251. SAMPLE.BAT:
  252. COPY C:\BATCH\CDSPACE.TXT C:\BATCH\RESET_CD.BAT > NUL
  253. CD >> C:\BATCH\RESET_CD.BAT
  254. REM  The lines that begin and end this sample batch
  255. REM   file can be added to any batch file that changes
  256. REM   directories so that the batch file can change
  257. REM   back to the directory from which it was invoked.
  258. CD
  259. CD \BATCH
  260. CD
  261. RESET_CD
  262.  
  263. -----------------------------------------------------------------
  264.                         Batch Refinements
  265.        (PC Magazine Vol 5 No 6 Mar 25, 1986 User-to-User)
  266.  
  267.      You can speed up execution of batch files two ways.  First,
  268. instead of using repeated ECHO statements to put long messages
  269. on-screen, have the program instead TYPE the contents of several small
  270. message files on the same disk.  This also lets you create attractive,
  271. centered screens with borders, arrows, etc.  Second, instead of using
  272. REMs to insert nonprinting comments, turn such comments into labels by
  273. putting a colon at the beginning of the line.  These look neater than
  274. REMs and will not print to the screen regardless of whether ECHO is
  275. off or on.
  276.                      All FOR DOS Redirection
  277.               (PC World April 1986 The Help Screen)
  278.  
  279.      This article addresses execution of the DOS command FOR with a
  280. utility that requires redirection fo standard input and output.
  281.      Suppose the utility STRIP.COM is used to convert WordStar files
  282. into ASCII files.  The command syntax is STRIP < infile > outfile
  283. where infile is the name of the WordStar file to be converted, and
  284. outfile is the name of the ASCII output file.  The command:
  285. FOR %Z IN (*.*) DO command will execute whatever DOS command replaces
  286. command for each of the file names listed between the parentheses.
  287. In using the FOR command to execute STRIP repeatedly for each WordStar
  288. file (none of which has a file name extension) to create ASCII files
  289. with the same name plus the extension .ASC, the command:
  290. FOR %Z IN (*.) DO STRIP < %Z > %Z.ASC  produces the "File not found"
  291. error message.
  292.      The solution:  When present in a DOS command, the redirection
  293. symbol < enables the command to receive its input from the file (or
  294. device) specified after the symbol instead of from the keyboard.
  295. In such instances, DOS verifies that the specified file exists before
  296. executing the command.  For example, try the command:  DIR < %Z.  %Z
  297. is the name of the file that DOS could not find when you invoke the
  298. FOR command.  Because the FOR command is not executed until DOS has
  299. completed its search for the input file, %Z is not interpreted as a
  300. DOS variable but rather as literal characters of a file name, i.e.,
  301. the redirection symbols in:  FOR %Z IN (*.) DO STRIP < %Z > %Z.ASC
  302. are part of the FOR command and not the STRIP command.  To solve the
  303. problem, first create the STRIP.BAT batch file:
  304.  
  305. STRIP < %1 > %1.ASC
  306.  
  307. Substituting STRIP.BAT %Z in place of STRIP < %Z > %Z.ASC in the
  308. original command works almost as intended, except that conversion
  309. will work only on the first matching file before the DOS prompt
  310. reappears.  This is because DOS doesn't permit a batch file to be
  311. nested within a FOR command (or inside another batch file), so control
  312. is not returned to the FOR command after the nested batch file has
  313. been executed.  You can, however, nest a call for another command
  314. processor.  When the second command processor has completed its
  315. function, control is passed back to the initial command processor,
  316. which then resumes its current task.  Having created STRIP.BAT,
  317. therefore, you can type:  FOR %Z IN (*.) DO \ COMMAND /C STRIP.BAT %Z
  318. and press Enter to convert the files.  Better yet, place that command
  319. in a batch file, which you may want to call BULKSTRP.BAT.  And don't
  320. forget that the variables of a FOR command in a batch file must be
  321. preceded by double % signs.
  322.  
  323. -----------------------------------------------------------------
  324.                      Batch of Documentation
  325.                (PC World April 1986 Star-Dot-Star)
  326.  
  327.      As utility programs accumulate, there's an obvious need for some
  328. means to keep track of their various features and commands.  You can
  329. maintain the information you need in separate files, one for each
  330. program.  Each program is named after the program it documents, but
  331. contains the extension .DOC.  For retrieval use a batch file called
  332. DOC.BAT that includes the following line:  TYPE %1.DOC | MORE.  The
  333. MORE command prevents text longer than 24 lines from scrolling off
  334. the screen but requires that the DOS filter program MORE.COM also be
  335. on the disk; you may choose to omit the command and the pipe symbol
  336. that precedes it.  Whenever you need information about a particular
  337. utility, simply type DOC followed by the program's name.  For example,
  338. type DOS WHEREIS to view on-line documentation for WHEREIS.COM.
  339.  
  340. -----------------------------------------------------------------
  341.                         Best Batch Branch
  342.        (PC Magazine Vol 5 No 8 Apr 29, 1986 User-to-User)
  343.  
  344.      Long batch files containing numerous "if ... goto" conditional
  345. statements tend to slow down dramatically as processing moves further
  346. along.  DOS searches slowly for each new label from the top of the
  347. file, yielding a pathetic 5- to 10-second delay, even on an AT, if
  348. the label occurs near the end of a long batch.  There is a way to get
  349. rid of all the labels and "if errorlevel ... goto" statements, allowing
  350. a batch file to work at top speed and still contain numerous
  351. conditional branches.
  352.      Most batches can be controlled with a simple Y(es) or other
  353. single-key response to each request.  The GETKEY technique described
  354. in an earlier User-to-User sets a different errorlevel for every
  355. response.  Because DOS returns a "true" if errorlevel <= the set
  356. value, batch files ordinarily require four "if errorlevel" tests to
  357. obtain "true" on Y or y but "false" on other keys.
  358.      GETYES.COM performs these tests, thereby removing them from the
  359. batch.  It sets errorlevel 255 for Y or y and errorlevel 0 for any
  360. other key.  This lets you directly perform an operation with the
  361. statement "if errorlevel 255 (perform some DOS function)".  GETYES.COM
  362. is created with GETYES.BAS below.
  363.      You can next "if" conditionals on one line of a batch file for
  364. further flexibility and control; for example, "if errorlevel 255 if
  365. exist filename (perform some DOS function)" or "if errorlevel 255 if
  366. x == %1 (perform some DOS function)".  This doesn't seem to be
  367. documented in the DOS manual.
  368.  
  369. 100 'GETYES.BAS
  370. 110 OPEN "GETYES.COM" AS #1 LEN=1
  371. 120 FIELD #1,1 AS D$
  372. 130 FOR B=1 TO 18
  373. 140 READ A$:LSET D$=CHR$(VAL("&H"+A$))
  374. 150 PUT #1:NEXT:CLOSE
  375. 160 DATA B4,00,CD,16,3C,59,74,04,3C
  376. 170 DATA 79,75,02,B0,FF,B4,4C,CD,21
  377.  
  378.      Editor's Note:  This technique makes batch branching a pleasure.
  379. If you want to use N and n rather than Y and y to trigger errorlevel,
  380. substitute 4E for 59 in line 160 and 6E for 79 in line 170, and change
  381. the reference from GETYES.COM to GETNO.COM.  To test this after
  382. creating the GETYES.COM program, use this TESTTHIS.BAT file:
  383.  
  384.  
  385.  
  386. echo off
  387. :start
  388. echo Hit y or Y or another key
  389. getyes
  390. if errorlevel 255 goto :yes
  391. goto :no
  392. :yet
  393. echo ...you said yes
  394. goto :continue
  395. :no
  396. echo ...you didn't hit y or Y
  397. :continue
  398. echo Now, want to quit (y/n)?
  399. getyes
  400. if errorlevel 255 goto :exit
  401. goto :start
  402. :exit
  403.  
  404.      The nesting abilities allow even more power.  To test these,
  405. revise the fifth line of TESTTHIS.BAT to read:
  406.  
  407. if errorlevel 255 if Z==%1 goto :yes
  408.  
  409. Then, if you execute TESTTHIS.BAT again, hitting Y or y at the first
  410. prompt will not result in a branch as it did earlier.  To make both
  411. of the nested conditions true, instead of executing the batch file by
  412. typing TESTTHIS, at the DOS prompt type:
  413.  
  414. TESTTHIS Z
  415.  
  416. and hit Y or y when asked.  The Z after the filename will replace the
  417. %1 parameter, and since both conditions (the errorlevel and the Z==Z)
  418. are true, the batch file will work as advertised.  If you try this, be
  419. sure to type in a capital Z; DOS, which much of the time converts
  420. lowercase keyboard inputs into uppercase ones, is case-sensitive here.
  421.  
  422. -----------------------------------------------------------------
  423.                   Automating a DOS 3.1 Upgrade
  424.          (PC Magazine Vol 5 No 10 May 27, 1986 PC Tutor)
  425.  
  426.      One of the differences between DOS 3.0 and 3.1 is the way the ECHO
  427. command works.  With DOS 3.0, batch files can turn ECHO off and then
  428. use the ECHO command to display instructions on the screen.  Using ECHO
  429. followed by two spaces to create blank lines works with DOS 3.0 but
  430. DOS 3.1 gives an "Echo is off" message on these lines.
  431.      This obstacle can be overcome.  Converting batch files is an easy
  432. job using the search-and-replace function in many text editors and word
  433. processors.  This conversion is an excellent example of a job you can
  434. handle rather elegantly using only normal DOS programs and facilities.
  435.      The secret is getting ECHO to print a blank line is to use the
  436. ASCII code 255 instead of a blank.  ASCII 255 shows up as a blank on
  437. the PC screen, but to DOS, it's a nonblank, so you won't get the "Echo
  438. is off" message.  You can create an ASCII 255 at your keyboard by
  439. pressing the Alt key, typing 255 on the number pad, and then releasing
  440. the Alt key.
  441.      Some text editors and word processors can handle ASCII 255 and
  442. some can't, but the job can be done easily with EDLIN.  EDLIN is tiny
  443. and fast, and ideal for doing fix-up jobs on text files less than 64K
  444. in length.
  445.      If you edit the batch files in EDLIN, you can do a search and
  446. replace to fix up the ECHO command with this EDLIN command:
  447.  
  448. 1.RECHO <F6>ECHO {255}
  449.  
  450.      The first number means "start a line 1."  The missing second
  451. number after the comma means to end at the last line in memory.  Next
  452. is R for "replace," followed immediately by the old string (ECHO and
  453. two blanks).  After the old string, press the F6 key (do not type the
  454. < and > brackets).  It will appear on the display as a ^Z.  Then type
  455. the new string: ECHO followed by a blank followed by the ASCII code
  456. 255.  The notation here means: press the Alt key, type 255 on the
  457. number pad, then release the Alt key.  This, incidentally, will appear
  458. as a blank on your display.  Since EDLIN's search and replace is case-
  459. sensitive, you'll probably have to do it for lowercase "echo" commands
  460. if you've also used these in your batch files.
  461.      Since EDLIN gets keyboard input through DOS (unlike most word
  462. processor and text editors), it can be used with redirection of
  463. standard input.  Begin by creating a small file (with EDLIN, of course)
  464. called REPLACE that looks like:
  465.  
  466. 1.RECHO <F6>ECHO {255}
  467. 2.RECHO <F6>Echo {255}
  468. 3.RECHO <F6>echo {255}
  469. E
  470.  
  471.      Don't type these lines as commands in EDLIN.  Instead, go into
  472. EDLIN's Insert mode (with the I command), and type them as data into
  473. the file.  These are keystrokes used below.  Note that three different
  474. search-and-replace strings are included for the three possible ways
  475. ECHO probably appears in your batch files.  The E command at the end
  476. tells EDLIN to end and save.
  477.      (If you ever have to edit REPLACE after you create it, use the /B
  478. option with EDLIN.  Since F6 is the same as a Ctrl-Z, which normally
  479. means "End of File," EDLIN will stop reading the file at the first
  480. Ctrl-Z unless it has the /B flag.)
  481.      Now to change a particular batch file, all you have to do is
  482. enter the command:
  483.  
  484. EDLIN batfile.BAT < REPLACE
  485.  
  486. and DOS will get all the keystrokes from REPLACE to do the search and
  487. replace for you.
  488.      Let's go a step further.  Start by creating a one-line batch file
  489. (called CHGBAT.BAT):
  490.  
  491. EDLIN %1 < REPLACE
  492.  
  493. Then create another one-line batch file called CHGALL.BAT:
  494.  
  495. FOR %%X IN (*.BAT) DO COMMAND /C CHGBAT %%X
  496.  
  497.      Now when you run CHGALL.BAT, it will execute CHGBAT.BAT for every
  498. batch file on the disk (or subdirectory).  Each time CHGBAT runs, it
  499. loads another batch file into EDLIN and uses REPLACE for the keystrokes
  500. to do the search and replace.
  501.      An interesting side-effect you'll encounter when you go through
  502. this process is that some batch files will get edited twice.  The
  503. reason is that EDLIN renames the old version of an edited file with
  504. an extension .BAK.  It creates a new directory entry to save the new
  505. version.  Thus, the FOR command in CHGALL.BAT comes across the file
  506. again.  You'll also notice that CHGALL.BAT and CHGBAT.BAT will
  507. themselves be edited by EDLIN during this process.  Neither of these
  508. two peculiarities caused any problems under DOS 3.1, however.
  509.      If you have batch files in a lot of different subdirectories on
  510. your hard disk, you could use SWEEP.COM (PC Mag Vol 4 No 23) to run
  511. CHGALL over all subdirectories on the hard disk with the command:
  512.  
  513. SWEEP CHGALL
  514.  
  515.      If you decide to do this, make sure to set your PATH command so
  516. that DOS can find CHGALL and CHGBAT from different subdirectories.
  517. Also modify CHGBAT.BAT to include the specific directory where REPLACE
  518. may be found.
  519.  
  520. -----------------------------------------------------------------
  521.                     Batch File Input Comment
  522.                (PC World June 1986 Star-Dot-Star)
  523.  
  524.      DOS does not have a batch file facility to accept input from the
  525. keyboard.  If you write batch files frequently, you may have been
  526. frustrated because then can't prompt the user to supply text that can
  527. be used as parameters for another operation.
  528.      One solution is KEYLINE.COM, which accepts a line of input from
  529. the keyboard and stores it in a specified file.  With I/O redirection,
  530. that file can supply the equivalent of typed input for another program;
  531. if the specified file name ends with .BAT, .COM, or .EXE, it can be run
  532. without modification.
  533.      To use KEYLINE.COM, type:  KEYLINE filename <Enter>.  (Be sure to
  534. type only one space between the command KEYLINE and the name of the
  535. file that is to store the user's input.)  Filename may include a DOS
  536. path, but be careful.  Although KEYLINE.COM will create the specified
  537. file when it does not exist, the program will erase the current
  538. contents of an existing specified file before it accepts and stores
  539. the user's response.
  540.      If for any reason the file cannot be created, KEYLINE.COM will
  541. set the batch ERRORLEVEL to 1 and exit, so you may wish to rest for
  542. that value immediately after executing KEYLINE.COM.  The batch file
  543. MENU.BAT demonstrates one way to use KEYLINE.COM.
  544.  
  545. 1 'KEYLINE.BAS:  RUN to create KEYLINE.COM
  546. 10 DEFINT A-Z:CLS:KEY OFF:DEF FNHEX(X$)=VAL("&h"+X$)
  547. 20 READ F$
  548. 30 LOCATE 5,1,1:PRINT "Checking DATA ....";
  549. 40 SUM-0:READ LN:IF LN<0 THEN 80
  550. 50 READ H$:IF VAL(H$)<0 THEN 70
  551. 60 SUM=(SUM+FNHEX(H$))*2:SUM=(SUM\256)+(SUM MOD 256):GOTO 50
  552. 70 READ CKSUM$:IF SUM=FNHEX(CKSUM$) THEN 40 ELSE GOTO 170
  553. 80 RESTORE:CLS:READ F$
  554. 90 LOCATE 5,1,1:PRINT "Press any key except ESC to create ";F$;": ";
  555. 100 A$=INPUT$(1):PRINT:IF A$=CHR$(27) THEN END
  556. 110 LOCATE 6,1:PRINT "Working ...";
  557. 120 OPEN F$ AS #1 LEN=1:FIELD #1,1 AS BX$
  558. 130 READ LN:IF LN<0 THEN 160
  559. 140 READ H$:IF VAL(H$)<0 THEN READ CKSUM$:GOTO 130
  560. 150 LSET BX$=CHR$(FNHEX(H$)):PUT #1:GOTO 140
  561. 160 CLOSE:PRINT:PRINT F$;" has been created.":END
  562. 170 PRINT:PRINT "Error in DATA line";STR$(LN);" :"
  563. 180 PRINT "Check DATA statements.":BEEP:END
  564. 1000 DATA "a:keyline.com"
  565. 1010 DATA 1,be,80,00,31,db,8a,1c,46,c6,00,00,46,89,f2,b9,20,-1,1b
  566. 1020 DATA 2,00,b4,3c,cd,21,72,32,89,c1,be,4f,01,c6,04,80,89,-1,5b
  567. 1030 DATA 3,f2,b8,0a,0c,cd,21,46,31,db,8a,1c,80,c3,02,c7,00,-1,58
  568. 1040 DATA 4,0a,1a,fe,c3,87,cb,46,89,f2,b4,40,cd,21,72,0a,b4,-1,a0
  569. 1050 DATA 5,3e,cd,21,72,04,b0,00,eb,02,b0,01,b4,4c,cd,21,-1,21,-1
  570.  
  571. MENU.BAT:
  572.  
  573. echo off
  574. cls
  575. echo Enter the command you wish to perform:
  576. keyline cmd.bat
  577. echo pause >> cmd.bat
  578. echo %0 >> cmd.bat
  579. cmd
  580.  
  581.